package com.server.dao;

import com.server.pojo.MobileApp;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.List;

@Repository
public interface MobileAppDao extends JpaRepository<MobileApp,Integer> {

    List<MobileApp> findByIdIn(List<Integer> ids);

    List<MobileApp> findByAccountIn(List<String> accounts);

    @Query("SELECT app FROM MobileApp app WHERE app.nowAlarm is not null and UNIX_TIMESTAMP(app.nowAlarm.alarmAt) + (app.nowAlarm.duration / 1000) > CURRENT_TIMESTAMP")
    List<MobileApp> alarmApps();


    @Query("SELECT app FROM MobileApp app WHERE ST_Distance_Sphere(POINT(app.longitude, app.latitude), POINT(:longitude, :latitude)) BETWEEN :minScope AND :maxScope")
    List<MobileApp> findScope(@Param("latitude") BigDecimal latitude, @Param("longitude") BigDecimal longitude, @Param("minScope")Long minScope, @Param("maxScope")Long maxScope);


    List<MobileApp> findByReceivedAllIsTrue();
    MobileApp findMobileAppByAccountAndPassword(String account,String password);
    MobileApp findByAccount(String account);

    MobileApp findByEmail(String email);
}

